package com.yh.homestay.controller;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.UserMemberEditResult;
import com.yh.homestay.pojo.UserMember;
import com.yh.homestay.service.UserMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理
 */
/**
 * 查看用户列表信息
 */
@Controller

public class UserMemberController {
    @Autowired
    private UserMemberService userService;

    @RequestMapping(value="/userList", produces = "application/json; charset=utf-8")
    @ResponseBody
    public HomeStayResult selectAll(Integer page, Integer limit, String userName){
        HomeStayResult resultMessage = userService.selectAll(page,limit,userName);
        return  resultMessage;
    }
    /**
     * 添加用户
     *
     * @param
     * @return
     */
@ResponseBody
    @RequestMapping("/addUser")
    public HomeStayResult addUser(UserMember userMember) {
    HomeStayResult homStayResult = userService.addUser(userMember);
    return homStayResult;
}

    /**
     * 修改用户信息
     *
     * @param
     * @return
     */
    @RequestMapping("/user-edit/{id}")
    @ResponseBody
    public HomeStayResult editMember(Integer id, String userName, String userNickname, String userPhone, Integer userIntegral){
        HomeStayResult update = userService.update(id,userName,userNickname,userPhone,userIntegral);
        return update;
    }

    /**
     * 删除用户信息
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/user-delete/{id}")
    public HomeStayResult deleteById(@PathVariable Integer id){
        HomeStayResult delete = userService.delete(id);
        return  delete;
    }
    /**
     * 批量删除
     */
    @ResponseBody
    @RequestMapping("/deleteUserS")
    public HomeStayResult delete(@RequestParam List<Integer> ids){
        HomeStayResult delete = userService.deleteUserS(ids);
        return  delete;
    }
    /**
     * 跳转编辑页面渲染数据
     */
    @RequestMapping("/user-edit/selectOne/{id}")
    @ResponseBody
    public UserMemberEditResult edituser(@PathVariable Integer id){

        return userService.selectone(id);
    }

    /**
     * 编辑页面传回id和数据展示
     * @param userMember
     * @return
     */
    @RequestMapping("/user-update")
    @ResponseBody
    public UserMemberEditResult updateUser(UserMember userMember){
    return userService.updateUserMember(userMember);

    }
}



